package backend.rss.items;

import java.util.Date;

import org.apache.commons.lang.StringEscapeUtils;

public class CommentItem implements Item
{
	private String id;
	private String comment;
	private Date postedDate;
	private AuthorItem author;
	
	public CommentItem(String id, String comment, Date postedDate, AuthorItem author)
	{
		this.id					= id;
		this.comment 			= comment;
		this.postedDate			= postedDate;
		this.author				= author;
	}
		
	/**
	 * @return the comment
	 */
	public String getComment()
	{
		return comment;
	}

	public String getStrippedComment()
	{
		/**
		 * Supports all known HTML 4.0 entities, including funky accents. 
		 * Note that the commonly used apostrophe escape character (&apos;) is not a legal entity 
		 * and so is not supported). 
		 */
		String noHTMLString = comment.replaceAll("\\<.*?>","").replaceAll("&apos;", "'");
		return StringEscapeUtils.unescapeHtml(noHTMLString);
	}
	
	/**
	 * @return the postedDate
	 */
	public Date getPostedDate()
	{
		return postedDate;
	}

	public String getId()
	{
		return id;
	}

	/**
	 * @return the author
	 */
	public AuthorItem getAuthor()
	{
		return author;
	}

	public String toString()
	{
		return "Comment by: "+ author+"\n" +
			   "Comment: "+ getComment()+"\n" +
			   "Date: "+ getPostedDate()+"\n";
	}
}
